﻿using System;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Messaging;

namespace AZProjekt
{
    class Program
    {
        private static void Main(string[] args)
        {
            //odczytywanie jsona z pliku .txt, znajdujacego sie w folderze Input
            Console.WriteLine("Prosze podac nazwe pliku: ");
            string fileName=Console.ReadLine();
           
            string fullname = Path.Combine(Directory.GetCurrentDirectory(), fileName);
            string removeString = fileName;
            int index = fullname.IndexOf(removeString, System.StringComparison.Ordinal);

            string cleanPath = (index < 0)? fullname: fullname.Remove(index, removeString.Length);
            cleanPath += "\\Input\\";
            cleanPath += fileName+".txt";
    
            if (!File.Exists(cleanPath))
            {
                Console.WriteLine("Dany plik nie istnieje!");
                Console.WriteLine("Aby zakończyć wciśnij enter");
                Console.ReadLine();
                return;
            }
            
            InputReader inputReader = new InputReader();
            if(!inputReader.IsJsonFile(fileName))
                return;
            int[][] edges = inputReader.JsonFileToArray(fileName);
            if(edges==null)
                return;
            if(!inputReader.CheckJsonFile(edges))
                return;

            MinEdgeCutAlgorithm algorithm = new MinEdgeCutAlgorithm();
            int minEdgeCut = algorithm.DoAlgorithm(edges);
            if (minEdgeCut != -1)
                Console.WriteLine("Spojnosc krawedziowa wynosi " + minEdgeCut);
            else
                Console.WriteLine("Graf jest niespojny!");
           
            Console.WriteLine("Aby zakończyć wciśnij enter");
            Console.ReadLine();

        }
    }
}
